package gui;

import gamemngr.GameMngr;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import resources.images.ImagesPath;

import com.swtdesigner.SWTResourceManager;

public class WinningDialog extends Dialog {

	protected Object result;
	protected Shell shell;
	private GameMngr game;
	private RiskGUI gui;

	/**
	 * Create the dialog
	 * @param parent
	 * @param style
	 */
	public WinningDialog(Shell parent, int style) {
		super(parent, style);
	}

	/**
	 * Create the dialog
	 * @param parent
	 */
	public WinningDialog(Shell parent, GameMngr game, RiskGUI gui) {
		this(parent, SWT.NONE);
		this.game = game;
		this.gui = gui;
	}

	/**
	 * Open the dialog
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		return result;
	}

	/**
	 * Create contents of the dialog
	 */
	protected void createContents() {
		shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
		shell.setLocation(RiskGUI.getNewPosition(getParent()));
		shell.setSize(500, 479);
		shell.setText("Congratulations");

		final Label label = new Label(shell, SWT.NONE);
		label.setBounds(115, 36, 287, 243);
		Image happyImage = Images.getImage("balloons.gif");
		label.setBackgroundImage(happyImage);
		label.setSize(happyImage.getBounds().width, happyImage.getBounds().height);

		final Label youWonLabel = new Label(shell, SWT.NONE);
		youWonLabel.setForeground(SWTResourceManager.getColor(255, 0, 0));
		youWonLabel.setFont(SWTResourceManager.getFont("Comic Sans MS", 22, SWT.BOLD));
		youWonLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
		youWonLabel.setText("You Won !!! your score:" + game.getCurrentPlayer().getTotalNumOfMoves());
		youWonLabel.setBounds(55, 310, 392, 49);

		final Button recordsTableButton = new Button(shell, SWT.NONE);
		recordsTableButton.setForeground(SWTResourceManager.getColor(255, 0, 0));
		recordsTableButton.setFont(SWTResourceManager.getFont("Comic Sans MS", 12, SWT.BOLD));
		recordsTableButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent arg0) {
				gui.showRecords();
			}
		});
		recordsTableButton.setText("Records Table");
		recordsTableButton.setBounds(186, 396, 132, 41);
	}

}
